﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using FbKPI.Model;
using FbKPI.Controller;

namespace FbKPI.Facade.Validator
{
    public class KPIAssignValidator
    {
        public string ValidateOnSave(KPIAssign KPIs)
        {
            string msg = "OK";
            if (KPIs.KPI == null)
                msg = "Please Enter KPI";
            if (KPIs.RGM == null)
                msg = "Please Enter RGM";
            if (KPIs.UoM == null)
                msg = "Please Enter UoM KPI";
            return msg;
        }

        public string ValidateOnUpdate(KPIAssign KPIs)
        {
            string msg = "OK";
            if (KPIs.KPI == null)
                msg = "Please Enter KPI";
            if (KPIs.RGM == null)
                msg = "Please Enter RGM";
            if (KPIs.UoM == null)
                msg = "Please Enter UoM KPI";
            return msg;
        }

        public string ValidateKPIAssignOnDelete(KPIAssign KPIs)
        {
            string msg = "OK";
            IList<KPIAchievement> Achievements = new KPIAchievementController().GetKPIAchievementTable(KPIs.KPI.Year, KPIs.ID);

            if (Achievements != null && Achievements.Count > 0)
            {
                foreach (KPIAchievement a in Achievements)
                {
                    if (a != null)
                    {
                        msg = "Invalid transaction, you are not allowed to unpick assessed KPI";
                        break;
                    }
                }
            }
            return msg;
        }
    }
}